/*
 * @Description:
 * @Version: 1.0
 * @Autor: chen_yt
 * @Date: 2022-06-01 10:21:17
 * @LastEditors: chen_yt
 * @LastEditTime: 2022-07-18 14:41:33
 */
import { saasPermission } from '@/saas/util'



/**
 * @description: 在需要鉴权处加入指令
 *               v-saas="['main', 'tenant','notSaas']"
 */
export function checkPermission(el, binding) {
    try {
        let tenantType = binding.value || []// 获取到 v-saas 的值
        let dataName = binding.arg
        if (!saasPermission(tenantType, dataName)) {
            // 没有权限 移除Dom元素
            el.parentNode && el.parentNode.removeChild(el)
        }
    } catch (error) {
        el.parentNode && el.parentNode.removeChild(el)
    }
}

/**
 * 权限判断指令
 */
export default {
    inserted: function (el, binding) {
        checkPermission(el, binding)
    },
    update: function (el, binding) {
        checkPermission(el, binding)
    }
}